#pragma once
#include "Defines.hpp"
#include "CybertronTaskRunnerPoolServer.hpp"
#include <map>
using namespace std;
typedef std::map<std::string, std::string>keyMap;
class CTaskRunnerPoolRestSrv {
public:
	static CTaskRunnerPoolRestSrv * GetInstance()
	{
		static CTaskRunnerPoolRestSrv instance;
		return &instance;
	}
	
	CTaskRunnerPoolRestSrv();
	virtual ~CTaskRunnerPoolRestSrv();

	bool init(int port, std::shared_ptr<CybertronTaskRunnerPoolServer>pServer);

	bool run();

	bool process_query(std::string query, keyMap& keyV);

	bool process_node_request(struct mg_connection *c, std::string groupId, std::string type, std::string tag);
	bool process_node_free(struct mg_connection *c, std::string groupId, std::string type, std::string id);
	bool process_node_list_stat(struct mg_connection *c, std::string groupId, std::string type);
	bool process_node_request_list(struct mg_connection *c, std::string groupId, std::string type);

	bool process_node_status_reset(struct mg_connection *c);
	bool process_node_report(struct mg_connection *c, std::string groupId, std::string type, std::string id, std::string command, keyMap* pKV);
	
	bool write_json(struct mg_connection *c, int code, std::string message, json body);

protected:
	std::string m_listen_on;
	std::shared_ptr<CybertronTaskRunnerPoolServer> mpServer;
};